<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {
      margin: 0;
    }

    ul {
      margin: 0;
      padding: 0;
      list-style: none;
    }

    a {
      color: inherit;
      text-decoration: none;
    }

    .box {
      width: 800px;
      margin: 100px auto;
      text-align: center;
    }

    .list {
      width: 800px;
    }

    /*in为选项卡普通状态，默认不显示*/
    .in,
    .in_active {
      display: none;
      height: 200px;
      font-size: 25px;
      line-height: 200px;
    }

    /*in_active为选项卡选中状态，选中后显示*/
    .in_active {
      display: block;
    }

    .conList {
      text-align: center;
      line-height: 50px;
    }

    /*con为按钮普通状态，默认无轮廓*/
    .con,
    .con_active {
      outline: 0;
      border: 1px solid skyblue;
    }

    /*con_active为按钮选中状态，选中后有1px的黑色轮廓*/
    .con_active {
      outline: 1px solid black;
    }

    button {
      background-color: aqua;
    }
  </style>
</head>

<body>
  <div class="box">
    <ul class="list">
      <li class="in_active" style="background-color: lightgreen">第一张选项卡</li>
      <li class="in" style="background-color: lightblue">第二张选项卡
        <button>下一页</button>
      </li>
      <li class="in" style="background-color: pink">第三张选项卡</li>
    </ul>
    <nav class="conList">
      <a class="con_active" href="javascript:;">第一个控制按钮</a>
      <a class="con" href="javascript:;">第二个控制按钮</a>
      <a class="con" href="javascript:;">第三个控制按钮</a>
    </nav>
  </div>

  <script>
    // 封装一个函数
    function Tab (obj) {
      // 展示部分
      this.oList = document.querySelector('.list')
      this.lis = document.querySelectorAll('li')

      // 选项卡控制部分
      this.conList = document.querySelector('.conList')
      this.as = document.querySelectorAll('a')

      // 变量设置
      // 选项卡张数
      this.num = this.lis.length
      this.cur = 0
      var that = this // 临时变量 这里的this指向Tab
      for (var i = 0; i < this.num; i++) {
        // 设置索引
        this.as[i].index = i

        // 给按钮添加点击事件
        this.as[i].onclick = function () {
          // 点击第几张
          console.log(this);// 这里的this指向a  a触发了事件
          that.cur = this.index
          that.switch()
        }
      }
    }
    // 原型上绑定切换方法
    Tab.prototype.switch = function () {
      for (var i = 0; i < this.num; i++) {
        this.lis[i].className = 'in';
        this.as[i].className = 'con';
      }
      this.lis[this.cur].className = 'in_active';
      this.as[this.cur].className = 'con_active';
    }
    let box = document.querySelector('.box')
    var tabl = new Tab(box)
  </script>






</body>

</html>